package com.ficus.road.maintain.core.model.zh;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ficus.road.maintain.core.model.RoadTypeEnum;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @author xiawen yang
 * @date 2022/8/19 下午8:14
 */
@Data
public class UnitScoreZH {
    private double total;

    private String unid;

    private String unitName;

    private double specialScore;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date inspectionTime;

    private double normalizationScore;

    private String unitid;

    private String sections;

    private double intelligenceScore;

    public UnitScore convert2UnitScore(UnitScoreZH zh, String date) {
        return UnitScore.builder()
                .id(zh.getUnid())
                .date(date)
                .companyName(zh.getUnitName())
                .companyId(zh.getUnitid())
                .unitId(zh.getSections())
                .inspectionTime(zh.getInspectionTime())
                .total(zh.getTotal())
                .specialScore(zh.getSpecialScore())
                .intelligenceScore(zh.getIntelligenceScore())
                .normalizationScore(zh.getNormalizationScore())
                .type(convertType(zh.getSections()))
                .build();
    }

    private String convertType(String unitId) {
        if (StringUtils.isEmpty(unitId) || unitId.contains("YHGL")) {
            return RoadTypeEnum.HIGHWAY.toString();
        } else {
            return RoadTypeEnum.ROAD.toString();
        }
    }
}
